package wanmei;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-9-7下午 08:26
 */
public class Test3 {
    public static void main(String[] args) {
        int[] jump = new int[]{2, 5, 1, 1, 1, 1};
        final int i = minJump(jump);
        System.out.println(i);
    }

    public static int minJump(int[] jump) {
        int res = 0;
        int len = 0;
        int max = 0;
        for (int i = 0; i < jump.length; ) {
            for (int j = 0; j < i; j++) {
                int len1 = j + jump[j];
                if (len1 > jump.length - 1) {
                    max = j;
                }
            }
            int tmp = jump[i];
            if (max != 0) {
                i = max;
                len = max;
                res++;
                res++;
                return res;
            } else {
                len += tmp;
                i = i + len;
                res++;
            }
            if (len > jump.length - 1) {
                return res;
            }
        }
        return 0;
    }
}
